package com.ghca.myinfo.system.controllers;

import com.ghca.myinfo.system.entities.User;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

/**
 * Created by gh on 2017/1/25.
 */
@ControllerAdvice
public class UserControllerAdvice {


    @ModelAttribute("currentUser")
    public User getCurrentUser(Authentication authentication) {
        if(authentication!=null) {
            Object principal = authentication.getPrincipal();
            if (principal instanceof User) {
                return (User) principal;
            }
        }
        return null;
    }
}
